package com.cooper.mediadb;

import com.cooper.mediadb.Actor;
import com.cooper.scrapemedialib.R;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.method.ScrollingMovementMethod;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public abstract class MediaInfoDialog<T extends Media> extends DialogFragment  {

	

	protected TextView credits;
	protected TextView director;
	protected TextView genre;
	protected TextView mpaa;
	protected TextView rating;
	protected TextView runtime;
	protected TextView tagline;
	protected TextView year;
	protected TextView plot;
	protected TextView actors;

	protected TextView title;

	protected View poltProgress;
	protected View directorProgress;
	protected View actorProgress;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View result = inflater
				.inflate(R.layout.media_details, container, false);

		title = (TextView) result.findViewById(R.id.media_details_title);
		credits = (TextView) result.findViewById(R.id.media_details_credits);

		director = (TextView) result.findViewById(R.id.media_details_director);
		plot = (TextView) result.findViewById(R.id.media_details_plot);

		genre = (TextView) result.findViewById(R.id.media_details_genre);
		mpaa = (TextView) result.findViewById(R.id.media_details_mpaa);
		rating = (TextView) result.findViewById(R.id.media_details_rating);
		runtime = (TextView) result.findViewById(R.id.media_details_runtime);
		tagline = (TextView) result.findViewById(R.id.media_details_tagline);
		year = (TextView) result.findViewById(R.id.media_details_year);
		actors = (TextView) result.findViewById(R.id.media_details_actors);
		actors.setMovementMethod(ScrollingMovementMethod.getInstance());

		poltProgress = result.findViewById(R.id.polt_progress);
		directorProgress = result.findViewById(R.id.director_progress);
		actorProgress = result.findViewById(R.id.actors_progress);
		return result;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setStyle(DialogFragment.STYLE_NORMAL, R.style.Custome_Dialog);
		setCancelable(true);
	}

	@Override
	public void onActivityCreated(Bundle savedState) {
		super.onActivityCreated(savedState);
		getDialog().setCanceledOnTouchOutside(true);
		// Display d = getWindow().getDefaultDisplay();
		// WindowManager.LayoutParams lp = getWindow().getAttributes();
		// lp.height = (int) (d.getHeight() * 1.0); //高度设置为屏幕的1.0
		// lp.width = (int) (d.getWidth() * 0.7); //宽度设置为屏幕的0.8
		// lp.alpha = 1.0f; //设置本身透明度
		// lp.dimAmount = 0.0f; //设置黑暗度
		// getWindow().setAttributes(lp);
		getDialog().getWindow().setGravity(Gravity.TOP);

		title.setText(getMedia().getTitle());
		setMovieDetailsViews();

	}
	
	protected abstract T getMedia();

	protected void setActorsText() {
		String actorText = "";
		for (Actor actor : getMedia().getActors()) {
			actorText += actor.getName()
					+ (actor.getRole() == null ? "" : " "
							+ getActivity().getResources().getString(
									R.string.media_details_of_role) + " "
							+ actor.getRole()) + "\n";
		}
		actors.setText(actorText);
		actors.scrollBy(0, 0);
	}



	protected void setMovieDetailsViews() {
		credits.setText(getMedia().getCredits());
		genre.setText(getMedia().getGenre());
		mpaa.setText(getMedia().getMpaa());
		rating.setText(getMedia().getRating());
		runtime.setText(getMedia().getRuntime());
		tagline.setText(getMedia().getTagline());
		year.setText(getMedia().getYear());
	}



}
